<?php

namespace app\api\controller;

use app\api\model\order\Order;
use app\home\model\MerchantModel;
use ulit\thirdPayment\SafePay;

class Timer
{


    public  function findOrder(){

        $restut=Order::select();

        foreach ($restut as $k=>$v){
            if ($v['status']==2){

                while (true){
                    $result=SafePay::getInstance()->query($v['order_sn']);
                    $arr=json_decode($result,true);
                    if($arr['result']['orderStatus']==1){
                        Order::where(['order_sn'=>$v['order_sn']])->update(['status'=>1]);
                        MerchantModel::where(['id'=>$v['merchant_id']])->dec('money',$v['commission'])->update();

                        break;
                    }
                    sleep(3);
                }

            }

        }
    }

    public function payorder(){

        for ($i=0;$i<10;$i++){
            $result=SafePay::getInstance()->query($v['order_sn']);
            $arr=json_decode($result,true);
            if($arr['result']['orderStatus']==1){
                Order::where(['order_sn'=>$v['order_sn']])->update(['status'=>1]);
                MerchantModel::where(['id'=>$v['merchant_id']])->dec('money',$v['commission'])->update();
            }
            sleep(3);
        }

    }
}